﻿#include "pch.h"

// int32_t (*off_10026250)() = &sub_1001E330;
char Buffer[] = "14.08";
char Str[] = "BP";
char aBp_0[] = "BP";
char aSt[256] = "$ST";
char aSt_0[256] = "$st";
char aStst[256] = "STst$";
char Source[4] = " BB";

char aNumberOfPeaksO_EN[29] = "Number of peaks out of limit";
//(不应超过%-d个)
char Format[100] = {'(', '\xB2', '\xBB', '\xD3', '\xA6', '\xB3', '\xAC', '\xB9',
                    '\xFD', '\x25', '\x2D', '\x64', '\xB8', '\xF6', ')', '\0'};
char aNumberOfSolven_EN[37] = "Number of solvent-peaks out of limit";

char aNoEnoughMemory_EN[17] = "No enough memory";
// 无足够内存
char aNoEnoughMemory_CN[12] = {'\xCE', '\xDE', '\xD7', '\xE3', '\xB9', '\xBB',
                               '\xC4', '\xDA', '\xB4', '\xE6', '\0', '\0'};

char aNumberOfTangen_EN[37] = "Number of tangent-peaks out of limit";
// 拖尾峰个数超限
char aNumberOfTangen_CN[16] = {'\xCD', '\xCF', '\xCE', '\xB2', '\xB7', '\xE5', '\xB8', '\xF6',
                               '\xCA', '\xFD', '\xB3', '\xAC', '\xCF', '\xDE', '\0', '\0'};

// 溶剂峰个数超限
char aNumberOfSolven0_CN[16] = {'\xC8', '\xDC', '\xBC', '\xC1', '\xB7', '\xE5', '\xB8', '\xF6',
                                '\xCA', '\xFD', '\xB3', '\xAC', '\xCF', '\xDE', '\x0', '\x0'};
char aNumberOfSolven0_EN[37] = "Number of solvent-peaks out of limit";

char aNoEnoughMemory0_EN[17] = "No enough memory";
// 无足够内存
char aNoEnoughMemory0_CN[12] = {'\xCE', '\xDE', '\xD7', '\xE3', '\xB9', '\xBB',
                                '\xC4', '\xDA', '\xB4', '\xE6', '\0', '\0'};

char aNumberOfTangen0_EN[37] = "Number of tangent-peaks out of limit";
// 拖尾峰个数超限
char aNumberOfTangen0_CN[16] = {'\xCD', '\xCF', '\xCE', '\xB2', '\xB7', '\xE5', '\xB8', '\xF6',
                                '\xCA', '\xFD', '\xB3', '\xAC', '\xCF', '\xDE', '\0', '\0'};

char aNumberOfPeaksO0_EN[29] = "Number of peaks out of limit";
char aNumberOfPeaksO1_EN[29] = "Number of peaks out of limit";
// 峰个数超限
char aNumberOfPeaksO0_CN[12] = {'\x0B7', '\x0E5', '\x0B8', '\x0F6', '\x0CA', '\x0FD',
                                '\x0B3', '\x0AC', '\x0CF', '\x0DE', '\x0', '\x0'};
// 峰个数超限
char aNumberOfPeaksO1_CN[12] = {'\xB7', '\xE5', '\xB8', '\xF6', '\xCA', '\xFD',
                                '\xB3', '\xAC', '\xCF', '\xDE', '\x0', '\x0'};
// 溶剂峰个数超限
char aNumberOfPeaksO2_CN[16] = {'\xC8', '\xDC', '\xBC', '\xC1', '\xB7', '\xE5', '\xB8', '\xF6',
                                '\xCA', '\xFD', '\xB3', '\xAC', '\xCF', '\xDE', '\x0', '\x0'};
// 峰个数超限
char aNumberOfPeaksO3_CN[12] = {'\xB7', '\xE5', '\xB8', '\xF6', '\xCA', '\xFD',
                                '\xB3', '\xAC', '\xCF', '\xDE', '\x0', '\x0'};

char aNoFindTheGoalP_EN[23] = "No find the goal peak!";
// 未找到目标峰！
char aNoFindTheGoalP_CN[16] = {'\xCE', '\xB4', '\xD5', '\xD2', '\xB5', '\xBD', '\xC4', '\xBF',
                               '\xB1', '\xEA', '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0'};

char aThePeakStartMu_EN[40] = "The peak-start must be on the baseline!";
// 起始点必须为基线点！
char aThePeakStartMu_CN[24] = {'\xC6', '\xF0', '\xCA', '\xBC', '\xB5', '\xE3', '\xB1', '\xD8',
                               '\xD0', '\xEB', '\xCE', '\xAA', '\xBB', '\xF9', '\xCF', '\xDF',
                               '\xB5', '\xE3', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThePeakStartCa_EN[66] = "The peak-start can't be front the left tangent-to-baseline point!";
// 起始点不能位于峰组的左基线切点之前！
char aThePeakStartCa_CN[40] = {'\xC6', '\xF0', '\xCA', '\xBC', '\xB5', '\xE3', '\xB2', '\xBB', '\xC4', '\xDC',
                               '\xCE', '\xBB', '\xD3', '\xDA', '\xB7', '\xE5', '\xD7', '\xE9', '\xB5', '\xC4',
                               '\xD7', '\xF3', '\xBB', '\xF9', '\xCF', '\xDF', '\xC7', '\xD0', '\xB5', '\xE3',
                               '\xD6', '\xAE', '\xC7', '\xB0', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aNoFindTheGoalP0_EN[23] = "No find the goal peak!";
// 未找到目标峰！
char aNoFindTheGoalP0_CN[16] = {'\xCE', '\xB4', '\xD5', '\xD2', '\xB5', '\xBD', '\xC4', '\xBF',
                                '\xB1', '\xEA', '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0'};

char aThePeakEndMust_EN[38] = "The peak-end must be on the baseline!";
// 结束点必须为基线点！
char aThePeakEndMust_CN[24] = {'\xBD', '\xE1', '\xCA', '\xF8', '\xB5', '\xE3', '\xB1', '\xD8',
                               '\xD0', '\xEB', '\xCE', '\xAA', '\xBB', '\xF9', '\xCF', '\xDF',
                               '\xB5', '\xE3', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThePeakStartCa0_EN[69] = "The peak-start can't be behined the right tangent-to-baseline point!";
// 结束点不能位于峰组的右基线切点之后！
char aThePeakStartCa0_CN[40] = {'\xBD', '\xE1', '\xCA', '\xF8', '\xB5', '\xE3', '\xB2', '\xBB', '\xC4', '\xDC',
                                '\xCE', '\xBB', '\xD3', '\xDA', '\xB7', '\xE5', '\xD7', '\xE9', '\xB5', '\xC4',
                                '\xD3', '\xD2', '\xBB', '\xF9', '\xCF', '\xDF', '\xC7', '\xD0', '\xB5', '\xE3',
                                '\xD6', '\xAE', '\xBA', '\xF3', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNoneOfO_EN[35] = "There is none of or only one peak!";
// 至少需要两个谱峰！
char aThereIsNoneOfO_CN[20] = {'\xD6', '\xC1', '\xC9', '\xD9', '\xD0', '\xE8', '\xD2', '\xAA', '\xC1', '\xBD',
                               '\xB8', '\xF6', '\xC6', '\xD7', '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0'};

char aCanTMoveTheSpl_EN[59] = "Can't move the split to the left of the tangent-peaks-end!";
// 分割线不能移至拖尾峰组结束点的左侧！
char aCanTMoveTheSpl_CN[40] = {'\xB7', '\xD6', '\xB8', '\xEE', '\xCF', '\xDF', '\xB2', '\xBB', '\xC4', '\xDC',
                               '\xD2', '\xC6', '\xD6', '\xC1', '\xCD', '\xCF', '\xCE', '\xB2', '\xB7', '\xE5',
                               '\xD7', '\xE9', '\xBD', '\xE1', '\xCA', '\xF8', '\xB5', '\xE3', '\xB5', '\xC4',
                               '\xD7', '\xF3', '\xB2', '\xE0', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aCanTMoveTheSpl0_EN[68] = "Can't move the split to the right of the front-tangent-peaks-start!";
// 分割线不能移至前切峰组结束点的右侧！
char aCanTMoveTheSpl0_CN[40] = {'\xB7', '\xD6', '\xB8', '\xEE', '\xCF', '\xDF', '\xB2', '\xBB', '\xC4', '\xDC',
                                '\xD2', '\xC6', '\xD6', '\xC1', '\xC7', '\xB0', '\xC7', '\xD0', '\xB7', '\xE5',
                                '\xD7', '\xE9', '\xBD', '\xE1', '\xCA', '\xF8', '\xB5', '\xE3', '\xB5', '\xC4',
                                '\xD3', '\xD2', '\xB2', '\xE0', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aNotLocateTheGo_EN[28] = "Not locate the goal-valley!";
// 未能定位目标谷点！
char aNotLocateTheGo_CN[20] = {'\xCE', '\xB4', '\xC4', '\xDC', '\xB6', '\xA8', '\xCE', '\xBB', '\xC4', '\xBF',
                               '\xB1', '\xEA', '\xB9', '\xC8', '\xB5', '\xE3', '\xA3', '\xA1', '\0', '\0'};

char aNotLocateTheGo0_EN[28] = "Not locate the goal-valley!";
// 未能定位目标谷点！
char aNotLocateTheGo0_CN[20] = {'\xCE', '\xB4', '\xC4', '\xDC', '\xB6', '\xA8', '\xCE', '\xBB', '\xC4', '\xBF',
                                '\xB1', '\xEA', '\xB9', '\xC8', '\xB5', '\xE3', '\xA3', '\xA1', '\0', '\0'};

char aCanTAddASplitI_EN[45] = "Can't add a split inside the negtaive peaks!";
// 不能在负峰组中添加分割线！
char aCanTAddASplitI_CN[28] = {'\xB2', '\xBB', '\xC4', '\xDC', '\xD4', '\xDA', '\xB8', '\xBA', '\xB7', '\xE5',
                               '\xD7', '\xE9', '\xD6', '\xD0', '\xCC', '\xED', '\xBC', '\xD3', '\xB7', '\xD6',
                               '\xB8', '\xEE', '\xCF', '\xDF', '\xA3', '\xA1', '\0', '\0'};

char aCanTAddASplitO_EN[67] = "Can't add a split on the rise edge of the front-tangent main-peak!";
// 不能在前切主峰的左边沿添加分割线！
char aCanTAddASplitO_CN[36] = {'\xB2', '\xBB', '\xC4', '\xDC', '\xD4', '\xDA', '\xC7', '\xB0', '\xC7',
                               '\xD0', '\xD6', '\xF7', '\xB7', '\xE5', '\xB5', '\xC4', '\xD7', '\xF3',
                               '\xB1', '\xDF', '\xD1', '\xD8', '\xCC', '\xED', '\xBC', '\xD3', '\xB7',
                               '\xD6', '\xB8', '\xEE', '\xCF', '\xDF', '\xA3', '\xA1', '\0', '\0'};

char aCanTAddASplitO0_EN[61] = "Can't add a split on the fall edge of the tangent main-peak!";
// 不能在拖尾主峰的右边沿添加分割线！
char aCanTAddASplitO0_CN[36] = {'\xB2', '\xBB', '\xC4', '\xDC', '\xD4', '\xDA', '\xCD', '\xCF', '\xCE',
                                '\xB2', '\xD6', '\xF7', '\xB7', '\xE5', '\xB5', '\xC4', '\xD3', '\xD2',
                                '\xB1', '\xDF', '\xD1', '\xD8', '\xCC', '\xED', '\xBC', '\xD3', '\xB7',
                                '\xD6', '\xB8', '\xEE', '\xCF', '\xDF', '\xA3', '\xA1', '\0', '\0'};

char aNotLocateTheGo1_EN[28] = "Not locate the goal-valley!";
// 未能定位目标谷点！
char aNotLocateTheGo1_CN[20] = {'\xCE', '\xB4', '\xC4', '\xDC', '\xB6', '\xA8', '\xCE', '\xBB', '\xC4', '\xBF',
                                '\xB1', '\xEA', '\xB9', '\xC8', '\xB5', '\xE3', '\xA3', '\xA1', '\0', '\0'};

char aNotLocateTheGo2_EN[28] = "Not locate the goal-valley!";
// 未能定位目标谷点！
char aNotLocateTheGo2_CN[20] = {'\xCE', '\xB4', '\xC4', '\xDC', '\xB6', '\xA8', '\xCE', '\xBB', '\xC4', '\xBF',
                                '\xB1', '\xEA', '\xB9', '\xC8', '\xB5', '\xE3', '\xA3', '\xA1', '\0', '\0'};

char aTheGoalTimeRan_EN[34] = "The goal time-range must be > 0 !";
// 目标区间的时间宽不能为0！
char aTheGoalTimeRan_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xB5', '\xC4',
                               '\xCA', '\xB1', '\xBC', '\xE4', '\xBF', '\xED', '\xB2', '\xBB', '\xC4', '\xDC',
                               '\xCE', '\xAA', '0', '\xA3', '\xA1', '\0', '\0', '\0'};

char aCanTLocateTheG_EN[34] = "Can't locate the goal time-range!";
// 不能定位目标区间0！
char aCanTLocateTheG_CN[20] = {'\xB2', '\xBB', '\xC4', '\xDC', '\xB6', '\xA8', '\xCE', '\xBB', '\xC4', '\xBF',
                               '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '0', '\xA3', '\xA1', '\0'};

char aCanTRecogniseA_EN[53] = "Can't recognise any peak inside the goal time-range!";
// 未能在目标区间内确定峰顶点(或底点)！
char aCanTRecogniseA_CN[40] = {'\xCE', '\xB4', '\xC4', '\xDC', '\xD4', '\xDA', '\xC4', '\xBF', '\xB1', '\xEA',
                               '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA', '\xC8', '\xB7', '\xB6', '\xA8',
                               '\xB7', '\xE5', '\xB6', '\xA5', '\xB5', '\xE3', '(', '\xBB', '\xF2', '\xB5',
                               '\xD7', '\xB5', '\xE3', ')', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNtAnyPe_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                               '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                               '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNtAnyPe0_EN[61] = "There is'nt any peak information inside the goal time-range!";
// 目标区间内未包含任何谱峰信息！
char aThereIsNtAnyPe0_CN[32] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4',
                                '\xC4', '\xDA', '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC',
                                '\xC8', '\xCE', '\xBA', '\xCE', '\xC6', '\xD7', '\xB7', '\xE5',
                                '\xD0', '\xC5', '\xCF', '\xA2', '\xA3', '\xA1', '\0', '\0'};

char aThereIsNtAnyPe1_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe1_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                                '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsOnlyOne_EN[51] = "There is only one peak inside the goal time-range!";
// 目标区间内仅包含了任何峰！
char aThereIsOnlyOne_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                               '\xBD', '\xF6', '\xB0', '\xFC', '\xBA', '\xAC', '\xC1', '\xCB', '\xC8', '\xCE',
                               '\xBA', '\xCE', '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0'};

char aThePeaksInside_EN[75] = "The peaks inside the goal time-range have already been skimmed vertically!";
// 目标区间内所有峰均已垂切！
char aThePeaksInside_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                               '\xCB', '\xF9', '\xD3', '\xD0', '\xB7', '\xE5', '\xBE', '\xF9', '\xD2', '\xD1',
                               '\xB4', '\xB9', '\xC7', '\xD0', '\xA3', '\xA1', '\0', '\0'};

char aThereIsNtAnyPe2_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe2_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                                '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aCanTMakeTangen_EN[63] = "Can't make tangent-skimming from the first of crossover peaks!";
// 不能从重叠峰组中的第一个峰开始拖尾切割！
char aCanTMakeTangen_CN[44] = {'\xB2', '\xBB', '\xC4', '\xDC', '\xB4', '\xD3', '\xD6', '\xD8', '\xB5',
                               '\xFE', '\xB7', '\xE5', '\xD7', '\xE9', '\xD6', '\xD0', '\xB5', '\xC4',
                               '\xB5', '\xDA', '\xD2', '\xBB', '\xB8', '\xF6', '\xB7', '\xE5', '\xBF',
                               '\xAA', '\xCA', '\xBC', '\xCD', '\xCF', '\xCE', '\xB2', '\xC7', '\xD0',
                               '\xB8', '\xEE', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereAreSomeTa_EN[92] =
    "There are some tangent peaks inside the goal time-range, can't make tangent-skimming again!";
// 目标区间内已包含了拖尾峰，不能再作拖尾切割！
char aThereAreSomeTa_CN[48] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                               '\xD2', '\xD1', '\xB0', '\xFC', '\xBA', '\xAC', '\xC1', '\xCB', '\xCD', '\xCF',
                               '\xCE', '\xB2', '\xB7', '\xE5', '\xA3', '\xAC', '\xB2', '\xBB', '\xC4', '\xDC',
                               '\xD4', '\xD9', '\xD7', '\xF7', '\xCD', '\xCF', '\xCE', '\xB2', '\xC7', '\xD0',
                               '\xB8', '\xEE', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNtAnyPe3_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe3_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                                '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aCanTMakeFrontT_EN[68] = "Can't make front-tangent-skimming from the last of crossover peaks!";
// 不能从重叠峰组中的最后一个峰开始向前斜切！
char aCanTMakeFrontT_CN[44] = {'\xB2', '\xBB', '\xC4', '\xDC', '\xB4', '\xD3', '\xD6', '\xD8', '\xB5',
                               '\xFE', '\xB7', '\xE5', '\xD7', '\xE9', '\xD6', '\xD0', '\xB5', '\xC4',
                               '\xD7', '\xEE', '\xBA', '\xF3', '\xD2', '\xBB', '\xB8', '\xF6', '\xB7',
                               '\xE5', '\xBF', '\xAA', '\xCA', '\xBC', '\xCF', '\xF2', '\xC7', '\xB0',
                               '\xD0', '\xB1', '\xC7', '\xD0', '\xA3', '\xA1', '\0', '\0'};

char aThereAreSomeTa0_EN[98] =
    "There are some tangent peaks inside the goal time-range, can't make front-tangent-skimming again!";
// 目标区间内已包含了拖尾峰，不能再作向前斜切！
char aThereAreSomeTa0_CN[48] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xD2', '\xD1', '\xB0', '\xFC', '\xBA', '\xAC', '\xC1', '\xCB', '\xCD', '\xCF',
                                '\xCE', '\xB2', '\xB7', '\xE5', '\xA3', '\xAC', '\xB2', '\xBB', '\xC4', '\xDC',
                                '\xD4', '\xD9', '\xD7', '\xF7', '\xCF', '\xF2', '\xC7', '\xB0', '\xD0', '\xB1',
                                '\xC7', '\xD0', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNtAnyPe4_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe4_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                                '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNtAnyPe5_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe5_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                                '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNtAnyPe6_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe6_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                                '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aThereIsNtAnyPe7_EN[49] = "There is'nt any peak inside the goal time-range!";
// 目标区间内未包含任何峰！
char aThereIsNtAnyPe7_CN[28] = {'\xC4', '\xBF', '\xB1', '\xEA', '\xC7', '\xF8', '\xBC', '\xE4', '\xC4', '\xDA',
                                '\xCE', '\xB4', '\xB0', '\xFC', '\xBA', '\xAC', '\xC8', '\xCE', '\xBA', '\xCE',
                                '\xB7', '\xE5', '\xA3', '\xA1', '\0', '\0', '\0', '\0'};

char aAnalysisDll_0[13] = "analysis.dll";
char Str2[] = "14.08";

AUTOIPARA gMakeIPara;
// int32_t dword_10027DC8 = 0;
// float flt_10027DCC = 0.0;
// float flt_10027DD0 = 0.0;

AUTOIPARA gLearnIPara;
// int32_t dword_10027DD8 = 0;
// float flt_10027DDC = 0.0;
// float flt_10027DE0 = 0.0;

char Destination[256] = {
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'};
int32_t gDrift = 0;
int32_t gSlope = 0;
int32_t gParaCalcCounter = 0;
int32_t gBufHeight = 0;
char Str1[0x400u];
// int32_t dword_10027F08 = 0;
int32_t gLanguage = 0; // 1033-english 0-chinese
char gTimeInfo[1024];
int32_t gMaxReal;
int32_t gMaxRedo;
int32_t gMaxChannels;
int32_t gRecursiveCounter;
char gResultItemName[32] = {'\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0',
                            '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0',
                            '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0', '\x0'};
int32_t gStdnoSelf[16];
double dblFive[5];
// int32_t dword_10028960;
// int32_t dword_10028964;
// double dblFive[1];
// __int64 qword_10028970;
// __int64 qword_10028978;
// __int64 qword_10028980;
// int32_t dword_10028990[1060];

// sub_10024E70
int32_t compareFloat(const void *f1, const void *f2)
{
    return (int32_t)((*(const float *)f1 - *(const float *)f2) * 10000.0);
};
// CompareFunction
int32_t CompareFunction(const void *a, const void *b)
{
    return *(int32_t *)a - *(int32_t *)b;
}

// sub_1000367C
int32_t compareFistAndSecond(const void *a, const void *b)
{
    int32_t *aInt = (int32_t *)a;
    int32_t *bInt = (int32_t *)b;
    int32_t ret;

    ret = aInt[0] - bInt[0];
    if (!ret)
    {
        ret = aInt[1] - bInt[1];
    }
    return ret;
}

// sub_10024EB0
int32_t compareSecondDouble(const void *dValue1, const void *dValue2)
{
    return (int32_t)((*((double *)dValue1 + 1) - *((double *)dValue2 + 1)) * 10000.0);
}

// sub_1001E4DD
double calcAmtMValue(TSTDAMTListItem *item, int32_t method)
{
    double result = 0;
    double amtK_10;
    double concFactor_10;

    if (item->metric.amount < 1.0e-30)
    {
        item->metric.amount = 1.0;
    }
    if (item->metric.injVolume < 1.0e-30)
    {
        item->metric.injVolume = 1.0;
    }
    if (item->metric.dilution < 1.0e-30)
    {
        item->metric.dilution = item->metric.injVolume / 1000.0;
    }
    if (item->metric.enrich < 1.0e-30)
    {
        item->metric.enrich = 1.0;
    }
    concFactor_10 = concFactorPow(item);
    if (item->metric.byCalib)
    {
        switch (method)
        {
        case 0:
            result = 100.0;
            break;
        case 1:
            result = 100.0;
            break;
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
            result = item->metric.injVolume / concFactor_10;
            break;
        default:
            return result;
        }
    }
    else
    {
        amtK_10 = amtKPow(item);
        switch (method)
        {
        case 0:
            result = 100.0;
            break;
        case 1:
            if (item->metric.amount >= 1.0e-30)
            {
                result = item->metric.amount;
            }
            else
            {
                result = 100;
            }
            break;
        case 2:
        case 5:
            result = amtK_10 * item->metric.amount / item->metric.enrich / concFactor_10;
            break;
        case 3:
        case 4:
        case 6:
            result = amtK_10 * item->metric.amount / item->metric.enrich * item->metric.injVolume / (item->metric.dilution * 1000.0) / concFactor_10;
            break;
        default:
            return result;
        }
    }
    return result;
}

// sub_1001E450
double concFactorPow(LPCTSTDAMTListItem item)
{
    return pow(10.0, (double)(WORD)item->metric.concFactor);
}

// sub_1001E47F
double amtKPow(LPCTSTDAMTListItem item)
{
    return pow(10.0, (double)(WORD)item->metric.amtK);
}

// sub_1001E4AE
double pow10_istdK(TDLLMETRIC *metric)
{
    return pow(10.0, (double)(WORD)metric->istdK);
}

// sub_10003A17
double getFte(TDLLResultListItem *pRes)
{
    float ret;

    if (pRes->fte <= 0.0)
    {
        ret = (float)pRes->te;
    }
    else
    {
        ret = pRes->fte;
    }
    return ret;
}

// sub_100039DC
double getFts(TDLLResultListItem *pRes)
{
    float ret;

    if (pRes->fts <= 0.0)
    {
        ret = (float)pRes->ts;
    }
    else
    {
        ret = pRes->fts;
    }
    return ret;
}

// sub_10003C0E
char *formatExceedError(char *Source, int32_t len)
{
    char Buffer[80];

    sprintf(Buffer, Format, len);
    // strncpy(Destination, Source, sizeof(Destination));/
    snprintf(Destination, sizeof(Destination), "%s", Source);
    strncat(Destination, Buffer, sizeof(Destination) - strlen(Destination));
    return Destination;
}

// sub_1000901A
int32_t searchSucceedAll(TDLLResultListItem *pRes, int32_t maxIndex)
{
    int32_t result;

    result = searchSucceedTypeCodeIdx(pRes, 0, maxIndex);
    return result < 0 ? 0 : result;
}

// sub_10009168
int32_t searchSucceedFrom(TDLLResultListItem *pRes, int32_t from)
{
    int32_t result;
    int32_t index;

    index = searchSucceedTypeCodeIdx(&pRes[from], from, from);
    if (index < 0)
    {
        result = from;
    }
    else
    {
        result = index;
    }
    return result;
}

// sub_100191C1
int32_t calcTailItemAndCheckPeak(int32_t *pRawBagBuffer, TDLLResultListItem *pRes, int32_t head, int32_t tail,
                                 float fy, float fx)
{
    float fte;
    int32_t calcResult;

    fte = (float)getFte(&pRes[tail]);
    calcResult = calcTailResultItem(pRawBagBuffer, pRes, head, tail, fy, fx);
    return checkTrPeak(pRawBagBuffer, pRes, head, tail, fy, fte) & calcResult;
}

// sub_10018F0B
int32_t calcTailResultItem(int32_t *pRawBagBuffer, TDLLResultListItem *pRes, int32_t head, int32_t tail, float fy,
                           float fx)
{
    float fte;
    int32_t buffer[128];
    int32_t i;
    int32_t i80;
    int32_t te;
    int32_t he;
    int32_t result;

    if (!pRawBagBuffer || !pRes)
    {
        return false;
    }
    if (head < 0 || tail < head)
    {
        return false;
    }
    if (getFte(&pRes[tail]) == getFts(&pRes[head]))
    {
        return false;
    }
    if (fx <= pRes[tail].tr)
    {
        return false;
    }
    i80 = -1;
    memset(buffer, 0, sizeof(buffer));
    te = pRes[tail].te;
    he = (int32_t)pRes[tail].he;
    fte = pRes[tail].fte;
    pRes[tail].fte = fx;
    pRes[tail].he = (float)getValueY(pRawBagBuffer, fx);
    calcTypeCodeRecursively(&pRes[head], tail - head, 0, buffer);
    i80 = -1;
    for (i = tail; i >= head; --i)
    {
        if (pRes[i].TypeCode[1] == C80)
        {
            i80 = i;
            break;
        }
    }
    pRes[tail].te = te;
    pRes[tail].he = (float)he;
    pRes[tail].fte = fte;
    result = false;
    if (i80 >= 0)
    {
        fte = (float)getFte(&pRes[i80 - 1]);
        result = calcTailResultItemValue(pRawBagBuffer, pRes, head, i80 - 1, fy, fte);
        head = i80;
        fy = (float)getFts(&pRes[i80]);
    }
    return calcTailResultItemValue(pRawBagBuffer, pRes, head, tail, fy, fx) || result;
}

// sub_10018C5D
int32_t checkTrPeak(int32_t *pRawBagBuffer, TDLLResultListItem *pRes, int32_t head, int32_t tail, float trMin,
                    float trMax)
{
    float fts;
    float fte;
    int32_t swapVar;
    int32_t intArray[128];
    int32_t i;
    int32_t i80;
    int32_t ts;
    int32_t hs;
    int32_t result;

    if (!pRawBagBuffer || !pRes)
    {
        return 0;
    }
    if (head > tail)
    {
        swapVar = head;
        head = tail;
        tail = swapVar;
    }
    if (head < 0)
    {
        return 0;
    }
    fts = (float)getFts(&pRes[head]);
    if (getFte(&pRes[tail]) == fts)
    {
        return 0;
    }
    if (trMin >= pRes[head].tr)
    {
        return 0;
    }
    memset(intArray, 0, sizeof(intArray));
    ts = pRes[head].ts;
    hs = (int32_t)pRes[head].hs;
    fts = pRes[head].fts;
    pRes[head].fts = trMin;
    pRes[head].hs = (float)getValueY(pRawBagBuffer, trMin);
    calcTypeCodeRecursively(&pRes[head], tail - head, 0, intArray);
    i80 = -1;
    for (i = head; i <= tail; ++i)
    {
        if (pRes[i].TypeCode[2] == C80)
        {
            i80 = i;
            break;
        }
    }
    pRes[head].ts = ts;
    pRes[head].hs = (float)hs;
    pRes[head].fts = fts;
    result = false;
    if (i80 >= 0)
    {
        fte = (float)getFte(&pRes[i80]);
        result = checkPeakSlope(pRawBagBuffer, pRes, head, i80, trMin, fte);
        head = i80 + 1;
        trMin = (float)getFts(&pRes[i80 + 1]);
    }
    if (!result)
    {
        result = checkPeakSlope(pRawBagBuffer, pRes, head, tail, trMin, trMax);
    }
    return result;
}

// sub_100136AD
double getValueY(int32_t *buffer, float xFloat)
{
    double result;
    float margin;
    int32_t xInt;

    xInt = (int32_t)xFloat;
    margin = xFloat - (float)xInt;
    result = buffer[xInt];
    if (margin <= 0.000001)
    {
    }
    else
    {
        result = (buffer[xInt + 1] - result) * margin + result;
    }
    return result;
}

// sub_1001814E
int32_t calcTypeCodeRecursively(TDLLResultListItem *pRes, int32_t tail, int32_t head, int32_t *idxArray)
{
    int32_t result;
    float fte;
    int32_t shouldUpdateSlope;
    float localSlope;
    float timeSpan;
    int32_t i;
    int32_t is78;
    char typeCode0;
    float slope;
    int32_t nextIdx;

    if (!head)
    {
        gRecursiveCounter = 0;
    }
    if (!head)
    {
        head = searchSucceedAll(pRes, tail);
    }
    for (i = head; i <= tail; ++i)
    {
        fte = (float)getFte(&pRes[i]);
        if (getFts(&pRes[head]) < fte)
        {
            break;
        }
    }
    if (i < tail)
    {
        fte = (float)getFte(&pRes[i]);
        timeSpan = (float)(fte - getFts(&pRes[head]));
        if (timeSpan == 0.0)
        {
            slope = 0.0;
        }
        else
        {
            slope = (pRes[i].he - pRes[head].hs) / timeSpan;
        }
        is78 = (pRes[0].TypeCode[0] & X7F) == C78;
        fte = (float)getFte(&pRes[i]);
        *idxArray = -1;
        while (i <= tail)
        {
            typeCode0 = pRes[i].TypeCode[0] & X7F;
            if (typeCode0 == C83 || typeCode0 == C36)
            {
                i = getPrevIndexNot84(pRes, tail, i);
            }
            else if (typeCode0 == C116)
            {
                i = getNextIndex36_115(pRes, tail, i);
            }
            timeSpan = (float)(getFte(&pRes[i]) - getFts(&pRes[head]));
            if (timeSpan == 0.0)
            {
                localSlope = 0.0;
            }
            else
            {
                localSlope = (pRes[i].he - pRes[head].hs) / timeSpan;
            }
            if (is78)
            {
                shouldUpdateSlope = localSlope >= slope;
            }
            else
            {
                shouldUpdateSlope = localSlope <= slope;
            }
            if (shouldUpdateSlope || getFte(&pRes[i]) == fte)
            {
                slope = localSlope;
                fte = (float)getFte(&pRes[i]);
                *idxArray = i;
            }
            ++i;
        }
        if (*idxArray < 0 || *idxArray >= tail)
        {
            *idxArray = 0;
            result = gRecursiveCounter;
        }
        else
        {
            nextIdx = ++*idxArray;
            pRes[nextIdx].TypeCode[1] = C80;
            pRes[nextIdx - 1].TypeCode[2] = C80;
            ++gRecursiveCounter;
            result = calcTypeCodeRecursively(pRes, tail, nextIdx, idxArray + 1);
        }
    }
    else
    {
        *idxArray = 0;
        result = gRecursiveCounter;
    }
    return result;
}

// sub_10018935
int32_t calcTailResultItemValue(int32_t *rawbagBuffer, TDLLResultListItem *pRes, int32_t, int32_t tail, float fts,
                                float fte)
{
    int32_t flag;
    float delta;
    float tr;
    int32_t idx;
    float vfts;
    float fte1;
    float vfte0;
    float vftei;
    int32_t i;
    int32_t k;
    int32_t j;

    if (fte <= fts || pRes[tail].tr <= fts)
    {
        return false;
    }
    fte1 = (float)getFte(&pRes[tail]);
    tr = pRes[tail].tr;
    vfts = (float)getValueY(rawbagBuffer, fts);
    vfte0 = (float)((getValueY(rawbagBuffer, fte) - vfts) / (fte - fts));
    idx = 0;
    for (i = (int32_t)tr; i <= (int32_t)fte; ++i)
    {
        vftei = (float)(((double)rawbagBuffer[i] - vfts) / ((double)i - fts));
        if ((pRes[tail].TypeCode[0] & X7F) == C78)
        {
            flag = vftei >= (double)vfte0;
        }
        else
        {
            flag = vftei <= (double)vfte0;
        }
        if (flag)
        {
            vfte0 = (float)(((double)rawbagBuffer[i] - vfts) / ((double)i - fts));
            idx = i;
        }
    }
    if (idx <= 0)
    {
        return false;
    }
    pRes[tail].te = idx;
    pRes[tail].he = (float)rawbagBuffer[idx];
    pRes[tail].hev = pRes[tail].he;
    if ((double)idx <= fte1)
    {
        if ((double)idx < fte1)
        {
            delta = (float)((float)(fte1 - (double)fte1));
            pRes[tail].Areae = pRes[tail].Areae - getValueY(rawbagBuffer, fte1) * delta;
            for (j = idx + 1; j <= (int32_t)fte1; ++j)
            {
                pRes[tail].Areae = pRes[tail].Areae - (double)rawbagBuffer[j];
            }
        }
    }
    else
    {
        delta = (float)((double)(int32_t)((int32_t)fte1 + 1) - fte1);
        pRes[tail].Areae = getValueY(rawbagBuffer, fte1) * delta + pRes[tail].Areae;
        for (k = (int32_t)fte1 + 2; k <= idx; ++k)
        {
            pRes[tail].Areae = (double)rawbagBuffer[k] + pRes[tail].Areae;
        }
    }
    return true;
}

// sub_100185E6
int32_t checkPeakSlope(int32_t *pRawBagBuffer, TDLLResultListItem *pRes, int32_t head, int32_t, float trMin,
                       float trMax)
{
    int32_t checkSlope;
    float ftsMargin;
    float minY;
    float currY;
    float localSlope;
    float maxY;
    int32_t found;
    float slope;
    float fts;
    float tr;
    int32_t i;
    int32_t k;
    int32_t j;

    if (trMin >= trMax || pRes[head].tr > trMax)
    {
        return 0;
    }
    fts = (float)getFts(&pRes[head]);
    tr = pRes[head].tr;
    if (trMax == tr)
    {
        tr = (float)((tr - fts + tr - fts) / 3.0 + fts);
    }
    maxY = (float)getValueY(pRawBagBuffer, trMax);
    minY = (float)getValueY(pRawBagBuffer, trMin);
    slope = (maxY - minY) / (trMax - trMin);
    found = -1;
    for (i = (int32_t)tr; i >= (int32_t)trMin; --i)
    {
        currY = (float)pRawBagBuffer[i];
        localSlope = (maxY - currY) / (trMax - i);
        if ((pRes[head].TypeCode[0] & X7F) == C78)
        {
            checkSlope = localSlope <= slope;
        }
        else
        {
            checkSlope = localSlope >= slope;
        }
        if (checkSlope)
        {
            slope = (maxY - currY) / (trMax - i);
            found = i;
        }
    }
    if (found < 0)
    {
        return false;
    }
    pRes[head].ts = found;
    pRes[head].hs = (float)pRawBagBuffer[found];
    pRes[head].hsv = pRes[head].hs;
    if (found <= fts)
    {
        if (found < fts)
        {
            ftsMargin = fts - (int32_t)fts;
            pRes[head].Areas = pRes[head].Areas - getValueY(pRawBagBuffer, fts) * ftsMargin;
            for (j = found + 1; j <= fts; ++j)
            {
                pRes[head].Areas = pRes[head].Areas - pRawBagBuffer[j];
            }
        }
    }
    else
    {
        ftsMargin = (int32_t)(fts + 1) - fts;
        pRes[head].Areas = getValueY(pRawBagBuffer, fts) * ftsMargin + pRes[head].Areas;
        for (k = (int32_t)fts + 2; k <= found; ++k)
        {
            pRes[head].Areas = pRawBagBuffer[k] + pRes[head].Areas;
        }
    }
    return true;
}

// sub_1000904C
int32_t searchSucceedTypeCodeIdx(TDLLResultListItem *pRes, int32_t idx, int32_t maxIndex)
{
    int32_t result;
    char typeCode0;
    char typeCode;

    result = -1;
    typeCode0 = pRes->TypeCode[0] & X7F;
    if (typeCode0 == C84)
    {
        while (idx > 0)
        {
            --idx;
            pRes++;
            typeCode = pRes->TypeCode[0] & X7F;
            if (typeCode == C83 || typeCode == C36)
            {
                return idx;
            }
            if (pRes->TypeCode[2] == C66 && typeCode != C84 && typeCode != C116)
            {
                return -1;
            }
        }
    }
    else if (typeCode0 == C116)
    {
        while (idx < maxIndex)
        {
            ++idx;
            pRes++;
            typeCode = pRes->TypeCode[0] & X7F;
            if (typeCode == C115 || typeCode == C36)
            {
                return idx;
            }
            if (pRes->TypeCode[1] == C66 && typeCode != C84 && typeCode != C116)
            {
                return -1;
            }
        }
    }
    return result;
}

// sub_100184EA
int32_t getPrevIndexNot84(TDLLResultListItem *pRes, int32_t tail, int32_t pos)
{
    int32_t result;
    int32_t i;

    result = tail;
    for (i = pos + 1; i < tail; ++i)
    {
        if ((pRes[i].TypeCode[0] & X7F) != C84 && pRes[i].tr > 0)
        {
            return i - 1;
        }
    }
    return result;
}

// sub_1001855B
int32_t getNextIndex36_115(TDLLResultListItem *pRes, int32_t tail, int32_t pos)
{
    int32_t i;
    int32_t result;
    char typeCode0;

    result = tail;
    for (i = pos + 1; i < tail; ++i)
    {
        typeCode0 = pRes[i].TypeCode[0] & X7F;
        if (typeCode0 != C84 && pRes[i].tr > 0)
        {
            if (typeCode0 == C115 || typeCode0 == C36)
            {
                result = i;
            }
            return result;
        }
    }
    return result;
}
char sub_10002ED7(IndexBuffer1 *pBuf)
{
    int32_t i;
    int32_t swap;

    if (!pBuf || !pBuf->flag)
    {
        return false;
    }
    if (pBuf->head > pBuf->tail)
    {
        swap = pBuf->head;
        pBuf->head = pBuf->tail;
        pBuf->tail = swap;
        qsort((void *)pBuf->pIndex2, pBuf->itemCount, sizeof(IndexBuffer2), CompareFunction);
        for (i = 0; i < pBuf->itemCount; ++i)
        {
            if (pBuf->pIndex2[i].head2 > pBuf->pIndex2[i].tail2)
            {
                swap = pBuf->pIndex2[i].head2;
                pBuf->pIndex2[i].head2 = pBuf->pIndex2[i].tail2;
                pBuf->pIndex2[i].tail2 = swap;
            }
        }
    }
    return true;
}

// sub_1000B1BF
int32_t calcTypeCodeFromBeginning(TDLLResultListItem *pRes, int32_t tail, int32_t *idxArray)
{
    return calcTypeCodeRecursively(pRes, tail, 0, idxArray);
}

// sub_10021D78
int32_t calcW50etc(TDLLResultListItem *pHead, void *pHead0, int32_t *smpHead, float freq, double xMinUnitK)
{
    int32_t result;
    double WL;
    double WR;

    TDLLResultListItem *pPrev = &pHead[-1];

    if (!pHead || !pHead0 || !smpHead)
    {
        return 0;
    }
    if ((int32_t)pHead->tr)
    {
        if ((int32_t)pHead->Height <= 0)
        {
            pHead->W50 = 0.0;
        }
        else
        {
            WL = 0.0;
            WR = 0.0;
            if (_EvalKHeightWEx(pHead, smpHead, 0.5, freq, xMinUnitK, &WL, &WR))
            {
                pHead->W50 = (float)(WL + WR);
            }
            else
            {
                pHead->W50 = 0;
            }
        }
        if (pHead->Height <= 0.0)
        {
            pHead->Sigma5 = 0.0;
        }
        else
        {
            pHead->Sigma5 = (float)(2.0 * pHead->Area / pHead->Height / xMinUnitK);
        }
        if (pHead->W50 <= 0.0)
        {
            pHead->Plates = 0.0;
        }
        else
        {
            pHead->Plates =
                (float)((double)pHead->RTime * 5.54 * pHead->RTime / ((double)pHead->W50 * pHead->W50));
        }
        if ((void *)pHead <= pHead0 || pHead->W50 + pPrev->W50 <= 0.0)
        {
            pHead->Resolution = 0.0;
        }
        else
        {
            pHead->Resolution =
                (float)(((double)pHead->RTime - pPrev->RTime) * 1.18 / ((double)pHead->W50 + pPrev->W50));
        }
        if ((int32_t)pHead->Height)
        {
            WL = 0.0;
            WR = 0.0;
            if (_EvalKHeightWEx(pHead, smpHead, 0.05, freq, xMinUnitK, &WL, &WR))
            {
                if (WL <= 0.0)
                {
                    pHead->Symmetry = 0.0;
                }
                else
                {
                    pHead->Symmetry = (float)((WL + WR) / (2.0 * WL));
                }
            }
            else
            {
                pHead->Symmetry = 0.0;
            }
        }
        else
        {
            pHead->Symmetry = 0.0;
        }
        memset(pHead->ReserveX.s, 0, 4u);
        result = true;
    }
    else
    {
        pHead->W50 = 0.0;
        pHead->Sigma5 = 0.0;
        pHead->Plates = 0.0;
        pHead->Resolution = 0.0;
        pHead->Symmetry = 0.0;
        memset(pHead->ReserveX.s, 0, 4u);
        result = false;
    }
    return result;
}

// sub_10021925
int32_t _EvalKHeightWEx(TDLLResultListItem *pHead, int32_t *smpHead, double k, float freq, double xMinUnitK,
                        double *lpWL, double *lpWR)
{
    double trR = 0.0;
    double trL = 0.0;

    double dWaveGapR;
    double dWaveGapR_;

    double dWaveGapL;
    double dWaveGapL_;

    *lpWL = 0.0;
    *lpWR = 0.0;
    if (!pHead || !smpHead || k <= 0.0 || k >= 1.0)
    {
        return false;
    }
    if (!(int32_t)pHead->tr)
    {
        return false;
    }
    if (calcTrLimt(pHead, smpHead, k, &trL, &trR))
    {
        if (trL <= 0.0)
        {
            if (pHead->Height <= 0.0)
            {
                dWaveGapL = (pHead->tr - pHead->ts) / (freq * 60.0);
            }
            else
            {
                dWaveGapL = 2.4 * pHead->ALeft / pHead->Height / xMinUnitK;
            }
            dWaveGapL_ = 2.35478 * dWaveGapL / 6.0;
            if (k == 0.5)
            {
                *lpWL = dWaveGapL_;
            }
            else
            {
                if (k <= 0.5)
                {
                    *lpWL = 2.0 * k * dWaveGapL_ + (1.0 - 2.0 * k) * dWaveGapL;
                }
                else
                {
                    *lpWL = (1.0 - k) * dWaveGapL_;
                }
            }
        }
        else
        {
            *lpWL = (pHead->tr - trL) / (freq * 60.0);
        }
        if (trR <= 0.0)
        {
            if (pHead->Height <= 0.0)
            {
                dWaveGapR = (pHead->te - pHead->tr) / (freq * 60.0);
            }
            else
            {
                dWaveGapR = 2.4 * pHead->ARight / xMinUnitK / pHead->Height;
            }
            dWaveGapR_ = 2.35478 * dWaveGapR / 6.0;
            if (k == 0.5)
            {
                *lpWR = dWaveGapR_;
            }
            else
            {
                if (k <= 0.5)
                {
                    *lpWR = 2.0 * k * dWaveGapR_ + (1.0 - 2.0 * k) * dWaveGapR;
                }
                else
                {
                    *lpWR = (1.0 - k) * dWaveGapR_;
                }
            }
        }
        else
        {
            *lpWR = (trR - pHead->tr) / (freq * 60.0);
        }
    }
    else
    {
        if (pHead->Height <= 0.0)
        {
            dWaveGapL = (pHead->tr - pHead->ts) / (freq * 60.0);
        }
        else
        {
            dWaveGapL = 2.4 * pHead->ALeft / pHead->Height / xMinUnitK;
        }
        if (pHead->Height <= 0.0)
        {
            dWaveGapR = (pHead->te - pHead->tr) / (freq * 60.0);
        }
        else
        {
            dWaveGapR = 2.4 * pHead->ARight / pHead->Height / xMinUnitK;
        }
        dWaveGapL_ = 2.35478 * dWaveGapL / 6.0;
        dWaveGapR_ = 2.35478 * dWaveGapR / 6.0;
        if (k == 0.5)
        {
            *lpWL = dWaveGapL_;
            *lpWR = dWaveGapR_;
        }
        else
        {
            if (k <= 0.5)
            {
                *lpWL = 2.0 * k * dWaveGapL_ + (1.0 - 2.0 * k) * dWaveGapL;
                *lpWR = 2.0 * k * dWaveGapR_ + (1.0 - 2.0 * k) * dWaveGapR;
            }
            else
            {
                *lpWL = (1.0 - k) * dWaveGapL_;
                *lpWR = (1.0 - k) * dWaveGapR_;
            }
        }
    }
    return true;
}

// sub_1000B1E2
double calcHsv(TDLLResultListItem *pRes, float fts, float hs, float slope)
{
    double result;

    if (pRes[0].tr == 0.0)
    {
        result = pRes[0].hs;
    }
    else
    {
        result = (getFts(pRes) - fts) * slope + hs;
    }
    return result;
}

// sub_1000B22A
double calcHev(TDLLResultListItem *pRes, float fte, float he, float slope)
{
    double result;

    if (pRes[0].tr == 0.0)
    {
        result = pRes[0].he;
    }
    else
    {
        result = (getFte(pRes) - fte) * slope + he;
    }
    return result;
}

// sub_1000B272
double calcHeadHsv(TDLLResultListItem *pRes, float fts, float hs0, float slope, float vfts, float hs)
{
    double result; // st7

    if (pRes->tr == 0.0)
    {
        result = hs;
    }
    else
    {
        result = (vfts - fts) * slope + hs0;
    }
    return result;
}

// sub_1000B2A6
double calcHeadHev(TDLLResultListItem *pRes, float fte, float he0, float slope, float vfte, float he)
{
    double result; // st7

    if (pRes->tr == 0.0)
    {
        result = he;
    }
    else
    {
        result = (vfte - fte) * slope + he0;
    }
    return result;
}

// sub_1000A5B3
bool isPeakType36_83(TDLLResultListItem *pRes)
{
    char TypeCode0;

    TypeCode0 = pRes->TypeCode[0] & X7F;
    return TypeCode0 == C83 || TypeCode0 == C36;
}

// sub_1000A5EF
bool isPeakType36_115(TDLLResultListItem *pRes)
{
    char TypeCode0;

    TypeCode0 = pRes->TypeCode[0] & X7F;
    return TypeCode0 == C115 || TypeCode0 == C36;
}

// sub_1000A62B
int32_t isTypeCode36(TDLLResultListItem *pRes)
{
    return (pRes->TypeCode[0] & X7F) == C36;
}

// sub_10020854
int32_t calcTrLimt(TDLLResultListItem *pHead, int32_t *smpHead, double k, double *trL, double *trR)
{
    int32_t typeCode;
    double currentV;
    double hev;
    double hsv;
    double hv;
    double ts;
    double tr;
    double te;
    double slope;
    bool canCalc;
    bool isLower;
    bool isHigher;
    bool doLeft;
    bool doRight;
    int32_t calcTr;
    double diffTr;
    double smpV;
    double smpSlope;

    if (!pHead || !smpHead || k <= 0.0 || k >= 1.0)
    {
        return false;
    }
    if (!(int32_t)pHead->tr)
    {
        return false;
    }
    ts = (double)pHead->ts;
    te = (double)pHead->te;
    tr = pHead->tr;
    hsv = pHead->hsv;
    hev = pHead->hev;
    if (te == ts)
    {
        slope = 0.0;
    }
    else
    {
        slope = (hev - hsv) / (te - ts);
    }
    hv = (tr - ts) * slope + hsv;
    typeCode = *pHead->TypeCode;

    double kk;
    if (typeCode == C78)
    {
        kk = -k;
    }
    else
    {
        kk = k;
    }
    currentV = hv + pHead->Height * kk;

    if (pHead->ts < (int32_t)pHead->tr)
    {
        if (typeCode == C78)
        {
            doLeft = hv - hsv >= currentV - pHead->hs;
        }
        else
        {
            doLeft = hv - hsv <= currentV - pHead->hs;
        }
    }
    else
    {
        doLeft = false;
    }
    if (pHead->te > (int32_t)pHead->tr)
    {
        if (typeCode == C78)
        {
            doRight = hev - hv <= pHead->he - currentV;
        }
        else
        {
            doRight = hev - hv >= pHead->he - currentV;
        }
    }
    else
    {
        doRight = false;
    }
    *trL = 0.0;
    if (doLeft)
    {
        calcTr = (int32_t)((1.0 - k) * ts + k * tr);
        diffTr = (int32_t)tr - calcTr;
        if (diffTr)
        {
            smpV = (double)smpHead[calcTr];
            smpSlope = (currentV - smpV) / (double)diffTr;
            if (typeCode == C78)
            {
                isHigher = smpSlope < slope;
            }
            else
            {
                isHigher = smpSlope > slope;
            }
            canCalc = false;
            if (isHigher)
            {
                while (calcTr < (int32_t)tr)
                {
                    smpV = (double)smpHead[calcTr];
                    smpSlope = (currentV - smpV) / (double)diffTr;
                    canCalc = typeCode == C78 ? smpSlope >= slope : smpSlope <= slope;
                    if (canCalc)
                    {
                        break;
                    }
                    ++calcTr;
                }
            }
            else
            {
                while (calcTr > (int32_t)ts)
                {
                    smpV = (double)smpHead[calcTr];
                    smpSlope = (currentV - smpV) / (double)diffTr;
                    if (typeCode == C78)
                    {
                        canCalc = smpSlope <= slope;
                    }
                    else
                        canCalc = smpSlope >= slope;
                    if (canCalc)
                    {
                        ++calcTr;
                        smpV = (double)smpHead[calcTr];
                        break;
                    }
                    --calcTr;
                }
            }
            if (canCalc)
            {
                if (smpSlope == slope)
                {
                    *trL = (double)calcTr;
                }
                else
                {
                    double smpPrevV = (double)smpHead[calcTr - 1];
                    if (smpV - smpPrevV - slope == 0.0)
                    {
                        *trL = (double)calcTr;
                    }
                    else
                    {
                        *trL = (double)calcTr - (smpV - currentV + (tr - (double)calcTr) * slope) / (smpV - smpPrevV - slope);
                    }
                }
            }
        }
        else
        {
            *trL = (double)calcTr;
        }
    }
    *trR = 0.0;
    if (doRight)
    {
        calcTr = (int32_t)((1.0 - k) * te + k * tr);
        diffTr = calcTr - (int32_t)tr;
        if (calcTr == (int32_t)tr)
        {
            *trR = (double)calcTr;
        }
        else
        {
            smpV = (double)smpHead[calcTr];
            smpSlope = (smpV - currentV) / (double)diffTr;
            if (typeCode == C78)
            {
                isLower = smpSlope > slope;
            }
            else
            {
                isLower = smpSlope < slope;
            }
            canCalc = false;
            if (isLower)
            {
                while (calcTr > (int32_t)tr)
                {
                    smpV = (double)smpHead[calcTr];
                    smpSlope = (smpV - currentV) / (double)diffTr;
                    canCalc = typeCode == C78 ? smpSlope <= slope : smpSlope >= slope;
                    if (canCalc)
                    {
                        break;
                    }
                    --calcTr;
                }
            }
            else
            {
                while (calcTr < (int32_t)te)
                {
                    smpV = (double)smpHead[calcTr];
                    smpSlope = (smpV - currentV) / (double)diffTr;
                    if (typeCode == C78)
                    {
                        canCalc = smpSlope >= slope;
                    }
                    else
                    {
                        canCalc = smpSlope <= slope;
                    }
                    if (canCalc)
                    {
                        --calcTr;
                        smpV = (double)smpHead[calcTr];
                        break;
                    }
                    ++calcTr;
                }
            }
            if (canCalc)
            {
                if (smpSlope == slope)
                {
                    *trR = (double)calcTr;
                }
                else
                {
                    double smpNextV = (double)smpHead[calcTr + 1];
                    if (smpV - smpNextV + slope == 0.0)
                    {
                        *trR = (double)calcTr;
                    }
                    else
                    {
                        *trR = (double)calcTr + (smpV - currentV - ((double)calcTr - tr) * slope) / (smpV - smpNextV + slope);
                    }
                }
            }
        }
    }
    return true;
}

// unknown_libname_9
// 对于64位机，unknown_libname的直接寻址是有问题的，因为结构中存在64位指针占8个字节。
// 所以直接寻址需全部变更为利用字段寻址。
int32_t unknown_libname_9(int32_t *pInt)
{
    return pInt[12];
}

// unknown_libname_8
int32_t unknown_libname_8(int32_t *pInt)
{
    return pInt[11];
}

// unknown_libname_5
int32_t unknown_libname_5(int32_t *pInt)
{
    return pInt[10];
}

// unknown_libname_6
int32_t unknown_libname_6(int32_t *pInt)
{
    return pInt[8];
}

// unknown_libname_16
void *unknown_libname_16(void **pInt)
{
    return pInt[0];
}

// sub_10022079
int32_t checkMetric(TDLLMETRIC *metric)
{
    int32_t result;

    if (metric)
    {
        result = checkMetricDeadTime(metric->deadTime);
    }
    else
    {
        result = false;
    }
    return result;
}

// sub_1002209F
int32_t checkMetricDeadTime(float)
{
    return true;
}

// sub_100228F1
int32_t isRTimeInBands(double idtTime, double band, double rTime, double tLeft, double tRight)
{
    bool between;

    between = false;
    if (band <= 0.0)
    {
        if (tLeft > 0.0 && tRight > 0.0)
        {
            between = rTime - tLeft <= idtTime && rTime + tRight >= idtTime;
        }
    }
    else
    {
        between = idtTime - band <= rTime && idtTime + band >= rTime;
    }
    return between;
}

// sub_1001FCC8
int32_t qryIdxFromArray(int32_t searchNo, int32_t count, int32_t *stdnoArray)
{
    int32_t i;
    int32_t notFound = -1;

    if (!count || !stdnoArray)
    {
        return notFound;
    }
    for (i = 0; i < count; ++i)
    {
        if (stdnoArray[i] == searchNo)
        {
            return i;
        }
    }
    return notFound;
}

// sub_10024C3E
double *calcDblFiveM1(double *arrValue, double *arrWeight, int32_t amtNum, int32_t oneOrZero, int32_t curveType)
{
    double d1;
    double d2;
    double d3;
    double *dd;
    int32_t i;
    double *areaDiff;
    double *weightDiff;

    areaDiff = new double[amtNum - oneOrZero];
    weightDiff = new double[amtNum - oneOrZero];
    memset(areaDiff, 0, sizeof(double) * (amtNum - oneOrZero));
    memset(weightDiff, 0, sizeof(double) * (amtNum - oneOrZero));
    for (i = 0; i < amtNum - oneOrZero; ++i)
    {
        areaDiff[i] = arrValue[i + oneOrZero] - arrValue[oneOrZero];
        weightDiff[i] = arrWeight[i + oneOrZero] - arrWeight[oneOrZero];
    }
    dd = calcDblFive(areaDiff, weightDiff, amtNum - oneOrZero, 1, curveType, 1);
    d1 =
        dd[1] - 2.0 * dd[2] * arrValue[oneOrZero] + 3.0 * dd[3] * arrValue[oneOrZero] * arrValue[oneOrZero];
    d2 = dd[2] - 3.0 * dd[3] * arrValue[oneOrZero];
    d3 = dd[3];
    dd[0] = dd[0] - dd[1] * arrValue[oneOrZero] + dd[2] * arrValue[oneOrZero] * arrValue[oneOrZero] - dd[3] * arrValue[oneOrZero] * arrValue[oneOrZero] * arrValue[oneOrZero] + arrWeight[oneOrZero];
    dd[1] = d1;
    dd[2] = d2;
    dd[3] = d3;
    delete[] areaDiff;
    delete[] weightDiff;
    return dd;
}

// sub_1002421F
double *calcDblFive(double *arrValue, double *arrWeight, int32_t amtNum, int32_t oneOrZero, int32_t curveType,
                    int32_t oneOrZero2)
{
    double *result;
    double d4[4];
    double d5;

    if (amtNum <= oneOrZero)
    {
        goto LABEL_2;
    }
    if (amtNum == oneOrZero + 1)
    {
        dblFive[0] = 0.0;
        dblFive[1] = arrWeight[oneOrZero] / arrValue[oneOrZero];
        dblFive[2] = 0.0;
        dblFive[3] = 0.0;
        dblFive[4] = 1.0;
        result = &dblFive[0];
    }
    else
    {
        if (curveType >= 4)
        {
        LABEL_2:
            dblFive[0] = 0.0;
            dblFive[1] = 0.0;
            dblFive[2] = 0.0;
            dblFive[3] = 0.0;
            dblFive[4] = 0.0;
            return &dblFive[0];
        }
        if (curveType == 2 && amtNum < oneOrZero + 3)
        {
            dblFive[0] = 0.0;
            curveType = 1;
        }
        else if (curveType == 3 && amtNum < oneOrZero + 4)
        {
            dblFive[3] = 0.0;
            curveType = 2;
        }
        memset(d4, 0, sizeof(d4));
        d5 = calcDblFourAndX(arrValue, arrWeight, amtNum, d4, curveType, oneOrZero2);
        if (d5 >= 0.0)
        {
            dblFive[0] = d4[0];
            dblFive[1] = d4[1];
            dblFive[2] = d4[2];
            dblFive[3] = d4[3];
            dblFive[4] = d5;
        }
        else
        {
            dblFive[0] = 0.0;
            dblFive[1] = 0.0;
            dblFive[2] = 0.0;
            dblFive[3] = 0.0;
            dblFive[4] = 0.0;
        }
        result = &dblFive[0];
    }
    return result;
}

// sub_1002452D
double calcDblFourAndX(double *arrValue, double *arrWeight, int32_t amtNum, double *d4, int32_t curveType,
                       int32_t oneOrZero2)
{
    double X;
    double dswap[16] = {
        0,
    };
    int32_t k;
    int32_t l;
    double sumValuePow;
    int32_t j;
    int32_t i;
    double product = 0.0f;
    int32_t oneOrZero;
    double sum[4] = {
        0,
    };
    double avgWeight;
    double varWeight;
    double varDiff;

    oneOrZero = oneOrZero2 == 1 ? 1 : 0;
    if (curveType > 3 || curveType < 1)
    {
        return 0.0;
    }
    if (oneOrZero2 == 1)
    {
        d4[0] = 0.0;
    }
    for (i = 0; i < 16; i++)
    {
        dswap[i] = 0;
    }
    for (i = oneOrZero; i <= curveType; ++i)
    {
        for (j = 0; j <= curveType; ++j)
        {
            dswap[4 * i + j] = 0.0;
            for (k = 0; k < amtNum; ++k)
            {
                product = 1.0;
                for (l = 1; l <= j + i; ++l)
                {
                    product = product * arrValue[k];
                }
                dswap[4 * i + j] = product + dswap[4 * i + j];
            }
        }
    }
    for (i = oneOrZero; i <= curveType; ++i)
    {
        sum[i] = 0.0;
        for (k = 0; k < amtNum; ++k)
        {
            product = arrWeight[k];
            for (l = 1; l <= i; ++l)
            {
                product = product * arrValue[k];
            }
            sum[i] = product + sum[i];
        }
    }
    for (i = oneOrZero; i <= curveType; ++i)
    {
        for (j = i + 1; j <= curveType; ++j)
        {
            if (fabs(dswap[4 * i + i]) < fabs(dswap[4 * j + i]))
            {
                for (l = i; l <= curveType; ++l)
                {
                    product = dswap[4 * j + l];
                    dswap[4 * j + l] = dswap[4 * i + l];
                    dswap[4 * i + l] = product;
                }
                product = sum[j];
                sum[j] = sum[i];
                sum[i] = product;
            }
        }
        for (j = i + 1; j <= curveType; ++j)
        {
            if (dswap[4 * i + i] != 0.0)
            {
                dswap[4 * i + j] = dswap[4 * i + j] / dswap[4 * i + i];
            }
        }
        if (dswap[4 * i + i] != 0.0)
        {
            sum[i] = sum[i] / dswap[4 * i + i];
        }
        dswap[4 * i + i] = 0;
        for (j = i + 1; j <= curveType; ++j)
        {
            for (l = i + 1; l <= curveType; ++l)
            {
                dswap[4 * j + l] = dswap[4 * j + l] - dswap[4 * i + l] * dswap[4 * j + i];
            }
            sum[j] = sum[j] - sum[i] * dswap[4 * j + i];
            dswap[4 * j + i] = 0;
        }
    }
    for (i = curveType; i >= oneOrZero; --i)
    {
        d4[i] = sum[i];
        for (j = i + 1; j <= curveType; ++j)
        {
            d4[i] = d4[i] - dswap[4 * i + j] * d4[j];
        }
    }
    i = 0;
    avgWeight = 0.0;
    while (i < amtNum)
    {
        avgWeight = avgWeight + arrWeight[i++];
    }
    if (amtNum > 0)
    {
        avgWeight = avgWeight / (double)amtNum;
    }
    i = 0;
    varWeight = 0.0;
    while (i < amtNum)
    {
        varWeight = (arrWeight[i] - avgWeight) * (arrWeight[i] - avgWeight) + varWeight;
        ++i;
    }
    i = 0;
    varDiff = 0.0;
    while (i < amtNum)
    {
        j = 0;
        sumValuePow = 0.0;
        while (j <= curveType)
        {
            sumValuePow = pow(arrValue[i], (double)j) * d4[j] + sumValuePow;
            ++j;
        }
        varDiff = (arrWeight[i] - sumValuePow) * (arrWeight[i] - sumValuePow) + varDiff;
        ++i;
    }
    if (varWeight == 0.0)
    {
        return 1.0;
    }
    X = 1.0 - varDiff / varWeight;
    if (X < 0.0)
    {
        X = -X;
    }
    return sqrt(X);
}

// sub_10023E95
int32_t sortAreaAndWeight(double *arrValue, double *arrWeight, int32_t amtNum, int32_t oneOrZero)
{
    int32_t i;
    int32_t j;
    int32_t count;
    int32_t NumOfElements;
    double *arrToSort;

    NumOfElements = amtNum;
    i = oneOrZero;
    while (i < NumOfElements)
    {
        if (arrValue[i] == 0.0 || arrWeight[i] == 0.0)
        {
            if (i < --NumOfElements)
            {
                memmove((void *)&arrValue[i], (const void *)&arrValue[i + 1],
                        sizeof(double) * (NumOfElements - i));
                memmove((void *)&arrWeight[i], (const void *)&arrWeight[i + 1],
                        sizeof(double) * (NumOfElements - i));
            }
        }
        else
        {
            ++i;
        }
    }
    i = oneOrZero;
    while (i < NumOfElements)
    {
        count = 1;
        j = i + 1;
        while (j < NumOfElements)
        {
            if (fabs(arrWeight[i]) <= 0.0 || fabs((arrWeight[j] - arrWeight[i]) / arrWeight[i]) >= 0.000001)
            {
                ++j;
            }
            else
            {
                arrValue[i] = arrValue[i] + arrValue[j];
                ++count;
                if (j + 1 >= NumOfElements)
                {
                    memset((void *)&arrValue[j], 0, sizeof(double));
                    memset((void *)&arrWeight[j], 0, sizeof(double));
                }
                else
                {
                    memmove((void *)&arrValue[j], (const void *)&arrValue[j + 1],
                            sizeof(double) * (NumOfElements - j - 1));
                    memmove((void *)&arrWeight[j], (const void *)&arrWeight[j + 1],
                            sizeof(double) * (NumOfElements - j - 1));
                }
                --NumOfElements;
            }
        }
        arrValue[i] = arrValue[i] / count;
        ++i;
    }
    arrToSort = new double[2 * amtNum];
    for (i = 0; i < NumOfElements; ++i)
    {
        arrToSort[2 * i] = arrValue[i];
        arrToSort[2 * i + 1] = arrWeight[i];
    }
    qsort(arrToSort, NumOfElements, 2 * sizeof(double), compareDouble);
    for (i = 0; i < NumOfElements; ++i)
    {
        arrValue[i] = arrToSort[2 * i];
        arrWeight[i] = arrToSort[2 * i + 1];
    }
    delete[] arrToSort;
    return NumOfElements;
}

// sub_1002234C
int32_t invalidAreaAndHeight(TDLLResultListItem *pRes, int32_t minArea, int32_t minHeight, char flag)
{
    if ((pRes->TypeCode[0] & X80) != 0 && !flag)
    {
        return false;
    }
    if (!pRes->tr)
    {
        return true;
    }
    if (minArea < pRes->Area)
    {
        return pRes->Height <= minHeight;
    }
    return true;
}

// sub_10006045
int32_t typeCode1Without84_116(TDLLResultListItem *pRes, int32_t flag)
{
    char typeCode0;
    int32_t result;

    result = appendTypeCodeChar(Str, pRes, 1);
    if (result)
    {
        typeCode0 = pRes->TypeCode[0] & X7F;
        if ((flag & 1) == 1 && typeCode0 == C84)
        {
            result = false;
        }
        if ((flag & 2) == 2 && typeCode0 == C116)
        {
            result = false;
        }
    }
    return result;
}

// sub_1000A9A4
int32_t typeCode2Without84_116(TDLLResultListItem *pRes, int32_t flag)
{
    char typeCode0;
    int32_t result;

    result = appendTypeCodeChar(aBp_0, pRes, 2);
    if (result)
    {
        typeCode0 = pRes->TypeCode[0] & X7F;
        if ((flag & 1) == 1 && typeCode0 == C84)
        {
            result = false;
        }
        if ((flag & 2) == 2 && typeCode0 == C116)
        {
            result = false;
        }
    }
    return result;
}

// sub_100060B2
int32_t appendTypeCodeChar(char *Str, TDLLResultListItem *pRes, int32_t offset)
{
    char typeCode0;

    typeCode0 = pRes->TypeCode[offset];
    if (!offset)
    {
        typeCode0 = pRes->TypeCode[0] & X7F;
    }
    return typeCode0 && strchr(Str, typeCode0);
}

// sub_1001090E
bool isPeakType36_83_115(TDLLResultListItem *pRes)
{
    char typeCode0;

    typeCode0 = pRes->TypeCode[0] & X7F;
    return typeCode0 == C83 || typeCode0 == C115 || typeCode0 == C36;
}

// sub_10011065
int32_t typeCode84BreakAt(TDLLResultListItem *pRes, int32_t num, int32_t idx)
{
    int32_t result = num;
    int32_t i;

    for (i = idx + 1; i < num; ++i)
    {
        if (!isTrHrEmpty(&pRes[i]) && (pRes[i].TypeCode[0] & X7F) != C84)
        {
            return i;
        }
    }
    return result;
}

// sub_100110D7
int32_t isTrHrEmpty(TDLLResultListItem *pRes)
{
    return !pRes->tr && !pRes->hr && pRes->ts && pRes->te;
}

// sub_10011136
int32_t typeCode116BreakAt(TDLLResultListItem *pRes, int32_t idx)
{
    int32_t i;
    int32_t result;

    result = -1;
    for (i = idx - 1; i >= 0; --i)
    {
        if (!isTrHrEmpty(&pRes[i]) && (pRes[i].TypeCode[0] & X7F) != C116)
        {
            return i;
        }
    }
    return result;
}

// sub_1000F8EE
int32_t searchIndexMaxOrMin(int32_t mode, int32_t *pRaw, float slope, int32_t time, int32_t *pHead, int32_t *pTail,
                            int32_t *pIdx, double val0)
{
    double vMinMax;
    double diffTop;
    double diffBottom;
    double acc;
    double tailVal;
    int32_t result;
    double diff;
    double headVal;
    int32_t idxMax;
    int32_t idxMin;
    double diffMax;
    int32_t idx;
    int32_t i;
    int32_t j;
    double diffMin;

    if (*pTail == *pHead)
    {
        return 0;
    }
    headVal = (double)pRaw[*pHead];
    tailVal = (double)pRaw[*pTail];
    diffMax = headVal;
    diffMin = headVal;
    acc = 0.0;
    if (val0 == 0.0)
    {
        val0 = (tailVal - headVal) / (double)(*pTail - *pHead);
    }
    idx = *pHead;
    idxMax = *pHead;
    idxMin = *pHead;
    while (idx <= *(int32_t *)pTail)
    {
        diff = (double)pRaw[idx] - acc;
        acc = acc + val0;
        if (diff > diffMax)
        {
            diffMax = diff;
            idxMax = idx;
        }
        if (diff < diffMin)
        {
            diffMin = diff;
            idxMin = idx;
        }
        ++idx;
    }
    result = 0;
    if (mode)
    {
        if (mode == 1)
        {
            if (idxMax != *pTail && (double)(int32_t)(5.0 * slope) < diffMax - headVal)
            {
                *pIdx = idxMax;
                result = 1;
                idx = idxMax;
                vMinMax = (double)pRaw[idxMax];
                acc = 0.0;
                for (i = idxMax; i < time; ++i)
                {
                    if ((double)pRaw[i] - acc < vMinMax)
                    {
                        idx = i;
                        vMinMax = (double)pRaw[i] - acc;
                    }
                    acc = acc + val0;
                }
                *pTail = idx;
            }
        }
        else if (mode == 2 && idxMax != *pHead && (double)(int32_t)(5.0 * slope) < diffMax - tailVal)
        {
            *pIdx = idxMax;
            result = 1;
            idx = idxMax;
            vMinMax = (double)pRaw[idxMax];
            acc = 0.0;
            for (j = idxMax; j > time; --j)
            {
                if ((double)pRaw[j] - acc < vMinMax)
                {
                    idx = j;
                    vMinMax = (double)pRaw[j] - acc;
                }
                acc = acc - val0;
            }
            *pHead = idx;
        }
    }
    else if (diffMax > headVal || diffMin < headVal)
    {
        diffTop = diffMax - headVal;
        diffBottom = headVal - diffMin;
        if (diffTop < diffBottom || (double)(int32_t)(5.0 * slope) >= diffTop)
        {
            if (diffBottom > diffTop && (double)(int32_t)(5.0 * slope) < diffBottom)
            {
                *pIdx = idxMin;
                result = 2;
            }
        }
        else
        {
            *pIdx = idxMax;
            result = 1;
        }
    }
    return result;
}

// sub_10012241
int32_t isTypeCode84_116(TDLLResultListItem *pRes)
{
    char typeCode0;

    typeCode0 = pRes->TypeCode[0] & X7F;
    return typeCode0 == C84 || typeCode0 == C116;
}

// sub_100121FF
int32_t isTypeCode84(TDLLResultListItem *pRes)
{
    return (pRes->TypeCode[0] & X7F) == C84;
}

// sub_100121D2
char setTypeCode0(TDLLResultListItem *pRes, char val)
{
    pRes->TypeCode[0] = val + (pRes->TypeCode[0] & X80);
    return pRes->TypeCode[0];
}

// sub_10012220
int32_t isTypeCode116(TDLLResultListItem *pRes)
{
    return (pRes->TypeCode[0] & X7F) == C116;
}

// sub_100135AC
double searchSteepPoint(int32_t *buffer, float xBegin, float xEnd, float xTo, int32_t flag)
{
    float currentSlope;
    float yBegin;
    float y;
    float yEnd;
    float result;
    float slope;
    int32_t i;

    if (xEnd == xBegin)
    {
        return xBegin;
    }
    result = xBegin;
    yEnd = (float)getValueY(buffer, xEnd);
    yBegin = (float)getValueY(buffer, xBegin);
    slope = (yEnd - yBegin) / (xEnd - xBegin);
    for (i = (int32_t)xBegin; i < (int32_t)xTo; ++i)
    {
        if ((double)i >= xEnd)
        {
            currentSlope = 0.0;
        }
        else
        {
            y = (float)buffer[i];
            currentSlope = (float)((yEnd - y) / (xEnd - (double)i));
        }
        if (flag)
        {
            if (currentSlope < (double)slope)
            {
                slope = currentSlope;
                result = (float)i;
            }
        }
        else if (currentSlope > (double)slope)
        {
            slope = currentSlope;
            result = (float)i;
        }
    }
    return result;
}

// sub_10013705
double searchSteepPointReverse(int32_t *buffer, float xBegin, float xEnd, float xFrom, int32_t flag)
{
    float currentSlope;
    float yEnd;
    float y;
    float result;
    float yBegin;
    float slope;
    int32_t i;

    if (xEnd == xBegin)
    {
        return xEnd;
    }
    result = xEnd;
    yBegin = (float)getValueY(buffer, xBegin);
    yEnd = (float)getValueY(buffer, xEnd);
    slope = (yEnd - yBegin) / (xEnd - xBegin);
    for (i = (int32_t)xEnd; i > (int32_t)xFrom; --i)
    {
        if (i <= xBegin)
        {
            currentSlope = 0.0;
        }
        else
        {
            y = (float)buffer[i];
            currentSlope = (y - yBegin) / (i - xBegin);
        }
        if (flag)
        {
            if (currentSlope > slope)
            {
                slope = currentSlope;
                result = (float)i;
            }
        }
        else if (currentSlope < slope)
        {
            slope = currentSlope;
            result = (float)i;
        }
    }
    return result;
}

// sub_10013BE5
int32_t checkTrPeak(int32_t *pHead, int32_t *pTail, float beginTime, float endTime, TDLLResultListItem *pRes,
                    int32_t resCount, float freq)
{
    int32_t j;
    int32_t i;
    float endTr;
    float beginTr;

    if (beginTime >= endTime)
    {
        beginTr = (float)(endTime * 60.0 * freq);
        endTr = (float)(beginTime * 60.0 * freq);
    }
    else
    {
        beginTr = (float)(beginTime * 60.0 * freq);
        endTr = (float)(endTime * 60.0 * freq);
    }
    if (beginTr >= pRes[0].tr)
    {
        for (i = 1; i < resCount; ++i)
        {
            if (beginTr > pRes[i - 1].tr && beginTr < pRes[i].tr)
            {
                *pHead = i;
                break;
            }
        }
        if (i == resCount)
        {
            return 0;
        }
    }
    else
    {
        *pHead = 0;
    }
    if (endTr <= pRes[resCount - 1].tr)
    {
        *pTail = -1;
        for (j = 0; j < resCount - 1; ++j)
        {
            if (endTr < pRes[j + 1].tr && endTr > pRes[j].tr)
            {
                *pTail = j;
                break;
            }
        }
        if (j == resCount - 1 || *(int32_t *)pTail < 0)
        {
            return false;
        }
    }
    else
    {
        *pTail = resCount - 1;
    }
    return *pHead <= *pTail + 1;
}

// sub_1001357C
int32_t appendTypeCode0ST(TDLLResultListItem *pRes)
{
    return appendTypeCodeChar(aSt, pRes, 0);
}

// sub_10013594
int32_t appendTypeCode0st(TDLLResultListItem *pRes)
{
    return appendTypeCodeChar(aSt_0, pRes, 0);
}

// sub_100143EA
int32_t appendTypeCode0STst(TDLLResultListItem *pRes)
{
    return appendTypeCodeChar(aStst, pRes, 0);
}

// sub_100151C2
int32_t searchPeakA(int32_t *head, int32_t *tail, float beginTime, float endTime, TDLLResultListItem *pRes,
                    int32_t num, float freq)
{
    int32_t next;
    int32_t prev;
    int32_t j;
    int32_t i;
    int32_t endCounter;
    int32_t beginCounter;

    if (beginTime >= endTime)
    {
        beginCounter = (int32_t)(endTime * 60.0 * freq);
        endCounter = (int32_t)(beginTime * 60.0 * freq);
    }
    else
    {
        beginCounter = (int32_t)(beginTime * 60.0 * freq);
        endCounter = (int32_t)(endTime * 60.0 * freq);
    }
    if (beginCounter >= pRes->te)
    {
        for (i = 1; i < num; ++i)
        {
            if ((pRes[i - 1].TypeCode[0] & X7F) == C83)
            {
                prev = pRes[i].ts;
            }
            else
            {
                prev = pRes[i - 1].te;
            }
            if ((pRes[i].TypeCode[0] & X7F) == C83 && i < num - 1)
            {
                next = pRes[i + 1].ts;
            }
            else
            {
                next = pRes[i].te;
            }
            if (beginCounter > prev && beginCounter < next)
            {
                *head = i;
                break;
            }
        }
        if (i == num)
        {
            return false;
        }
    }
    else
    {
        *head = 0;
    }
    if (endCounter <= pRes[num - 1].ts)
    {
        for (j = 0; j < num - 1; ++j)
        {
            if (endCounter > pRes[j].ts && endCounter < pRes[j + 1].ts)
            {
                *tail = j;
                break;
            }
        }
        if (j == num)
        {
            return false;
        }
    }
    else
    {
        *tail = num - 1;
    }
    return *head <= *tail;
}

// sub_1001513F
int32_t typeCode1Break84_116Prev(TDLLResultListItem *pRes, int32_t tail, char flag)
{
    while (tail > 0 && !typeCode1Without84_116(&pRes[tail], flag))
    {
        --tail;
    }
    return tail;
}

// sub_1001517E
int32_t typeCode2Break84_116Next(TDLLResultListItem *pRes, int32_t num, int32_t head, char flag)
{
    while (head < num - 1 && !typeCode2Without84_116(&pRes[head], flag))
    {
        ++head;
    }
    return head;
}

// sub_100241F3
int32_t compareDouble(const void *a, const void *b)
{
    int32_t result;

    if (*(double *)a <= *(double *)b)
    {
        result = -1;
    }
    else
    {
        result = 1;
    }
    return result;
}

// unknown_libname_17
int32_t unknown_libname_17(uint32_t *_this)
{
    return _this[2];
}

// ATL::CDynamicAccessor::GetColumnCount
int32_t atlGetColumnCount(uint32_t *_this)
{
    return *((int32_t *)_this + 3);
}

// sub_1001A040
double divideX10(float val)
{
    return val / 10.0;
}

// Concurrency::details::ContextBase::GetExecutingCollection
void *ccGetExecutingCollection(void *_this)
{
    return *((void **)_this + 13);
}

// Concurrency::details::ContextBase::SetExecutingCollection
void ccSetExecutingCollection(void *_this, void *val)
{
    *((void **)_this + 13) = val;
}

// sub_10019C10
double divideX3_10(float a, float b)
{
    return (double)a * 3.0 / (10.0 * b);
}

// sub_10019C40
double multiplyX10(float f1)
{
    return (double)(f1 * 10.0);
}

// sub_10019C60
double multiplyX(float f1, float f2)
{
    return f1 * f2;
}

// sub_10017912
int32_t isValidChannel(int32_t chn)
{
    return chn <= gMaxChannels && gAnalPoolList[chn].isOpened;
}
